﻿layui.config({
    base: '/Lib/layui/extend/'
}).extend({
    formSelects: 'formSelects-v4'
}).use(['form', 'layedit', 'layer','laydate', 'jquery'], function () {
    var form = layui.form, layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        player = parent.layer || layui.layer,
        laydate = layui.laydate; 

    var salarySettlementLogic = {
        //初始化
        init: function () {

            self = this;

            this.Parameters = {
                settlementData: undefined,
                saveUrl: "/Staff/Salary/Settlement"
            };

            this.initPage();

            this.bindEvent();

        },
        //初始化列表
        initPage: function () {

            //日期
            laydate.render({
                elem: '#MyYearMonth',
                format: 'yyyy-MM',
                type: 'month',
                value: new Date()
            });

            //获取信息
            self.Parameters.settlementData = GrdLayUI.getUrlParameters();

            form.render();

        },
        //绑定事件
        bindEvent: function () {

            //监听提交
            form.on('submit(modifyButton)', self.logicFunc.saveInfo);

            //关闭
            $("#btnClose").on("click", self.logicFunc.close);

        },
        //逻辑方法
        logicFunc: {

            //保存数据
            saveInfo: function () {

                var modifyInfo = GrdLayUI.initParamsData($("#modify-form"));

                var json = {
                    parameters: {
                        PayMethodID: modifyInfo.PayMethodID,
                        PayMethodName: $("#PayMethodID option:selected").text(),
                        MyYear: modifyInfo.MyYearMonth.split("-")[0],
                        MyMonth: modifyInfo.MyYearMonth.split("-")[1],
                        Question: modifyInfo.Question,
                        Rmark: modifyInfo.Rmark,
                        BegTime: self.Parameters.settlementData.dBeginTime,
                        EndTime: self.Parameters.settlementData.dEndTime,
                        CheckProjectNo: self.Parameters.settlementData.ProjectNo,
                        UserNo: self.Parameters.settlementData.UserNo,
                        Name: self.Parameters.settlementData.Name,
                        PYM: self.Parameters.settlementData.PYM,
                        Sex: self.Parameters.settlementData.Sex,
                        Code: self.Parameters.settlementData.Code,
                        BankNo: self.Parameters.settlementData.BankNo,
                        BankName: self.Parameters.settlementData.BankName,
                        DepNo: self.Parameters.settlementData.DepNo,
                        WorkTypeID: self.Parameters.settlementData.WorkTypeID,
                        WorkTypeName: self.Parameters.settlementData.WorkTypeName,
                        WorkDay: self.Parameters.settlementData.WorkDay, //已审核的考勤
                        NoWorkDay: self.Parameters.settlementData.NoWorkDay,//未审核的考勤
                        //DayMoney: self.Parameters.settlementData.DayMoney,//员工档案的日工资
                        OverTime: self.Parameters.settlementData.OverTime,//加班小时
                        //OverMoney: self.Parameters.settlementData.OverMoney,//加班小时工资
                        TOverMoney: self.Parameters.settlementData.TOverMoney,//合计加班工资
                        LoanMoney: self.Parameters.settlementData.LoanMoney,//借款
                        LoanBackMoney: self.Parameters.settlementData.LoanBackMoney,//还款
                        AmountMoney: self.Parameters.settlementData.AmountMoney,//计件工资
                        TWorkMoney: self.Parameters.settlementData.TWorkMoney,//考勤X工资=应发工资
                        RealMoney: self.Parameters.settlementData.RealMoney,//始发工资就是减去借款（本来是还有各种补贴，那个是后面领导追加（交通补贴，奖金等））
                    }
                }
                GrdLayUI.ajaxPost({
                    url: self.Parameters.saveUrl,
                    data: json,
                    success: function (result) {
                        if (result.Code == 1000) {

                            GrdLayUI.msg(result.Msg, "成功", function () {
                                //获取窗口索引
                                var index = player.getFrameIndex(window.name);
                                //关闭子页面
                                player.close(index);
                                //刷新父页面
                                window.parent.location.reload();
                            });

                        } else {
                            GrdLayUI.msg(result.Msg, "警告");
                        }
                    }
                });
            },
            //取消
            close: function () {
                player.closeAll();
            }
        },
        //工具
        tools: {
        }
    };
    salarySettlementLogic.init();
});
